package cn.school.demo.ui.edit

import android.view.View
import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import cn.school.demo.MyApplication
import cn.school.demo.pojo.User
import com.blankj.utilcode.util.LogUtils
import java.lang.Exception

class UpdatePhoneViewModel : ViewModel() {
    private val _visibleOne = MutableLiveData<Int>()
    val visibleOne: LiveData<Int>
        get() = _visibleOne
    private val _visibleTwo = MutableLiveData<Int>()
    val visibleTwo: LiveData<Int>
        get() = _visibleTwo
    private val _newPhone = MutableLiveData<String?>()
    val newPhone: LiveData<String?>
        get() = _newPhone
    private var _code = MutableLiveData<String?>()
    val code: LiveData<String?>
        get() = _code
    private val _user = MutableLiveData<User>()
    val user: LiveData<User> get() = _user
    private lateinit var _getCode: LiveData<String>
    val getCode: LiveData<String> get() = _getCode

    init {
        _visibleOne.value = View.VISIBLE
        _visibleTwo.value = View.GONE
        _newPhone.value = null
        _user.value = MyApplication.user
    }

    fun setGetCode(c: LiveData<String>){
        _getCode = c
    }

    fun setUser(u: User){
        _user.value = u
    }

    fun modifyVisible() {
        if (_visibleOne.value == View.VISIBLE && _visibleTwo.value == View.GONE) {
            _visibleOne.value = View.GONE
            _visibleTwo.value = View.VISIBLE
        } else if (_visibleOne.value == View.GONE && _visibleTwo.value == View.VISIBLE) {
            _visibleOne.value = View.VISIBLE
            _visibleTwo.value = View.GONE
        } else {
            throw RuntimeException()
        }
    }

    fun setNewPhone(phone: String) {
        LogUtils.d(phone)
        _newPhone.value = phone
    }

    fun setCode(code:String) {
        _code.value = code
    }

}